<?php
/**
 *
 * @author      : arvin<huxudong@dalingpao.com>
 * @copyright(c): 17-9-29
 * @version     : $id$
 */
class Admin_Page_Abstract extends Q_Abstract_Page
{

    protected static $_sysConf = array();
    protected static $_ctlName = '';
    protected static $_actName = '';

    public function __construct(Q_Request $input, Q_Response $output)
    {
        self::$_ctlName = $input->ctlName;
        self::$_actName = $input->actName;

        $output->layout('Default');
        self::$_sysConf = Q_Config::get(array('Global'));

        $input->conf = $output->conf = self::$_sysConf;

        if (Q_Request::resolveType() !== Q_Request::AJAX) {
            $this->_loadClientScript();
            $this->_loadPlugin($input, $output);
        }
    }

    /**
     * 加载客户端脚本
     */
    private function _loadClientScript()
    {
        $conf = Q_Config::get('Admin_ClientScript');
        $key  = strtoupper(self::$_ctlName . "|" . self::$_actName);

        $data = $conf['*'];
        if (!empty($conf[$key])) {
            $data = array_merge_recursive($data, $conf[$key]);
        }
        foreach ($data as $fileType => $row) {
            foreach ($row as $pos => $file) {
                Q_ClientScript::addFile($file, $fileType, $pos);
            }
        }

        return true;
    }

    /**
     * 加载插件
     *
     * @param Q_Request  $input
     * @param Q_Response $output
     */
    private function _loadPlugin(Q_Request $input, Q_Response $output)
    {
        //侧边栏
        $output->sidebar = Admin_Plugin_Sidebar::getSidebar($input, $output);

        //Tab
        $output->tab = Admin_Plugin_Tab::getTab($input, $output);

    }
}